#!/usr/bin/env python3
# encoding: utf-8

"""
@version: 1.0
@author: 周永波
@file: appUtils.py
@time: 2020/8/4 15:08
"""
import logging
import os
import yaml
log = logging.getLogger(__name__)

def dict_get(dictObj, keys, default=None):
    temp = dictObj
    for key in keys:
        temp = temp.get(key, None)
        if temp is None:
            return default
    return temp

# # 字典取值
# def dict_get(dictObj, keys=[]):
#     temp = dictObj
#     for key in keys:
#         temp = temp.get(key, None)
#         if temp is None:
#             return
#     return temp

# yml 文件类容获取
def yaml_get(filePath):
    if os.path.exists(filePath) is False:
        log.error(filePath + " not found file")
        return None
    file = open(filePath, 'r', encoding='utf-8')
    return yaml.load(file.read(), Loader=yaml.FullLoader)

def dict_to_object(dictObj, obj=None):
    if not isinstance(dictObj, dict):
        return dictObj
    for k,v in dictObj.items():
        setattr(obj,k,v)
    return obj